package com.atguigu.gulimall.product.controller;

import com.atguigu.common.utils.PageUtils;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.product.service.AttrService;
import com.atguigu.gulimall.product.vo.AttrRespVo;
import com.atguigu.gulimall.product.vo.AttrVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;



/**
 * 商品属性
 *
 * @author joe
 * @email joe@gmail.com
 * @date 2020-06-13 13:42:01
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Autowired
    private AttrService attrService;

    // /**
    //  * 列表
    //  */
    // @RequestMapping("/list")
    // // @RequiresPermissions("product:attr:list")
    // public R list(@RequestParam Map<String, Object> params){
    //     PageUtils page = attrService.queryPage(params);
    //
    //     return R.ok().put("page", page);
    // }

    /**
     * 查询
     */
    @GetMapping("/{type}/list/{catId}")
    public R list(@RequestParam Map<String, Object> params, @PathVariable("type") String type, @PathVariable("catId") Long catId){
        PageUtils page = attrService.queryPage(params, type, catId);
        return R.ok().put("page", page);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    // @RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrRespVo attr = attrService.getAttr(attrId);
        return R.ok().put("attr", attr);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    // @RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
		attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    // @RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    // @RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeAttr(attrIds);
        return R.ok();
    }


}
